from . import fmt


class CodeTable:
	"""CodeTable class document:
	Author: Lemonix
	Introduce: ClassTableTool 主类，提供加词、删词，调序等功能
	"""
	def __init__(self,
			mb_str, 
			sep='\t',
			is_break_up=True,
			is_code_first=True):
		option = {
			'code_sep': sep,
			'is_reverse': not is_code_first
		}

		classified = fmt.classify(mb_str, **option)
		if not is_break_up:
			fmt.break_up(classified, is_change=True)

		merged = fmt.merge(classified)
		self.merged = merged


	def add(self, code, content, order=-1):
		pass


	def remove(self, *group):
		# 目标不在 merged 中
		if group[0] not in self.merged:
			return

		# 有码无选，就清空
		if len(group) == 0:
			self.merged[group[0]].clear()

		if len(group) >= 2:
			if group[0] not in self.merged:
				return
			# 遍历删词
			for content in group[1:]:
				self.merged[group[0]].remove(content)
		

	def single(self):
		pass


	def word(self):
		pass

		